<template>
	<view class="content">
		<view class="pic">
			<view class="er">
				<!-- <image src="../../../static/dai.png" mode=""></image> -->
				<image :src="myurl" mode=""></image>
			</view>
			<view class="baocun" @click="invite()">保存二维码</view>
			<view class="num">{{code}}</view>
			<view class="ma">邀请码</view>
		</view>
	</view>
</template> 

<script>
import getdata from '@/common/ajax.js';	
import QR from "@/common/wxqrcode.js"
	export default {	
		data() {
			return {
				myurl:'',
				code:''
			}
		},
		onLoad() {
			this.code = uni.getStorageSync('code') 
			let img = QR.createQrCodeImg('http://12cv.cc/api/index/register?code='+this.code,{
			     size: parseInt(300)//二维码大小  
			})
			this.myurl = img
		},
		methods: {
			invite(){
				 var pages = getCurrentPages();    
					  var page = pages[pages.length - 1];  
					console.log("当前页"+pages.length-1);
					  var bitmap=null;  
					  var currentWebview = page.$getAppWebview();
					  bitmap = new plus.nativeObj.Bitmap('amway_img');  
					  // 将webview内容绘制到Bitmap对象中  
					  currentWebview.draw(bitmap,function(){  
						  console.log('截屏绘制图片成功');  
						  bitmap.save( "_doc/a.jpg"  
						  ,{}   
						  ,function(i){  
							  console.log('保存图片成功：'+JSON.stringify(i));  
							  uni.saveImageToPhotosAlbum({  
								  filePath: i.target,  
								  success: function () {  
									  bitmap.clear(); //销毁Bitmap图片  
									  uni.showToast({  
										  title: '保存图片成功',   
										  mask: false,  
										  duration: 1500  
									  });    
								  }  
							  });  
						  }  
						  ,function(e){  
							  uni.showToast({
								  title: '保存图片失败',   
								  mask: false,  
								  duration: 1500  
							  });  
							  console.log('保存图片失败：'+JSON.stringify(e));  
						  });  
					  },function(e){  
						  uni.showToast({
							  title: '截屏绘制图片失败',   
							  mask: false,  
							  duration: 1500  
						  });  
						  console.log('截屏绘制图片失败：'+JSON.stringify(e));  
					  });  
					  //currentWebview.append(amway_bit);      
			}
		}
	}
</script>

<style lang="scss">
.content{
	width: 100vw;
	height: 100vh;
	background: url(../../../static/yaoqing.png) no-repeat;
	background-size:100% 100%;
	.pic{
		width: 508rpx;
		height: 525rpx;
		border-radius: 30rpx;
		// background-color: rgba(0,0,0,0.3);
		position: absolute;
		top:665rpx;
		left:120rpx;
		.er{
			width: 220rpx;
			height: 220rpx;
			margin: 0 auto;
			margin-top: 30rpx;
			image{
				width: 220rpx;
				height: 220rpx;	
			}
		}
		.baocun{
			width: 210rpx;
			height: 60rpx;
			line-height: 60rpx;
			background: #1578F2;
			border-radius: 20rpx;
			font-size: 24rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #FFFFFF;
			text-align: center;
			margin: 0 auto;
			margin-top: 25rpx;
		}
		.num{
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #F2154E;
			// margin: 0 auto;
			text-align: center;
			margin-top: 50rpx;
		}
		.ma{
			font-size: 24rpx;
			font-family: PingFang SC;
			color: #000000;
			// margin: 0 auto;
			text-align: center;
			margin-top: 20rpx;
		}
	}
	
}	
</style>
